﻿//#define SKIN_DEBUG

using LogSystem;
using System;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
using Yoozoo.Core.Extensions.Engine;

namespace Yoozoo.Gameplay.RTS
{
    public class GPUInstance_SpawnObject
    {
        public int instancingId;
        private Transform m_transform;
        private Transform m_parent;
        public Matrix4x4 localToWorldMatrix;

        public int indexInArray;

        private Vector3 positionOffset;
        private Vector3 angleOffset;
        private Vector3 scale;

        public float shadowHeight;
        public float shadowAlpha;
        
        public void Initial(Transform transform)
        {
            m_transform = transform;
            positionOffset = m_transform.localPosition;
            angleOffset = m_transform.localEulerAngles;
            scale = m_transform.localScale;
        }

        public void SetParent(Transform transform)
        {
            m_parent = transform;
            m_transform.SetParent(transform);
            m_transform.transform.localPosition = positionOffset;
            m_transform.transform.localEulerAngles = angleOffset;
            m_transform.transform.localScale = scale;
        }

        public void SetTransform(Transform transform)
        {
            m_transform = transform;
        }

        public void SetTransformOffset(Transform transform)
        {
            positionOffset = transform.localPosition;
            angleOffset = transform.localEulerAngles;
            scale = transform.localScale;
        }
        
        public void Update()
        {
            /*var forward = m_transform.forward;
            var f = Quaternion.Euler(angleOffset) * forward;
            var q = Quaternion.LookRotation(f);
            var scale = m_transform.lossyScale;
            scale = new Vector3(scale.x * this.scale.x,scale.y * this.scale.y,scale.z * this.scale.z);
            var positionOffset = q * this.positionOffset;*/
            localToWorldMatrix = Matrix4x4.TRS(m_transform.position,m_transform.rotation,scale);
        }

        public void SetShadowHeight(float shadowHeight)
        {
            this.shadowHeight = shadowHeight;
        }

        public void SetShadowAlpha(float alpha)
        {
            this.shadowAlpha = alpha;
        }
    }
}